package com.ynding.spring.idea.ddd.core.service.wechat.repository.impl;

import com.ynding.spring.idea.ddd.common.dal.wechat.dao.BalanceDAO;
import com.ynding.spring.idea.ddd.common.dal.wechat.dao.StatementDAO;
import com.ynding.spring.idea.ddd.common.dal.wechat.dao.WalletDAO;
import com.ynding.spring.idea.ddd.common.dal.wechat.dao.WechatAccountDAO;
import com.ynding.spring.idea.ddd.common.dal.wechat.po.BalancePO;
import com.ynding.spring.idea.ddd.common.dal.wechat.po.StatementPO;
import com.ynding.spring.idea.ddd.common.dal.wechat.po.WalletPO;
import com.ynding.spring.idea.ddd.common.dal.wechat.po.WechatAccountPO;
import com.ynding.spring.idea.ddd.core.service.wechat.convert.BalanceConvert;
import com.ynding.spring.idea.ddd.core.service.wechat.convert.StatementConvert;
import com.ynding.spring.idea.ddd.core.service.wechat.convert.WalletConvert;
import com.ynding.spring.idea.ddd.core.service.wechat.convert.WechatAccountConvert;
import com.ynding.spring.idea.ddd.core.service.wechat.repository.AccountRepository;
import com.ynding.spring.idea.ddd.core.model.wechat.domain.WechatAccount;
import com.ynding.spring.idea.ddd.core.model.wechat.dp.PhoneNumber;
import com.ynding.spring.idea.ddd.core.model.wechat.entity.Balance;
import com.ynding.spring.idea.ddd.core.model.wechat.entity.Statement;
import com.ynding.spring.idea.ddd.core.model.wechat.entity.Wallet;
import com.ynding.spring.idea.ddd.core.model.wechat.factory.BalanceFactory;
import com.ynding.spring.idea.ddd.core.model.wechat.factory.StatementFactory;
import com.ynding.spring.idea.ddd.core.model.wechat.factory.WalletFactory;
import org.springframework.stereotype.Repository;

/**
 * <p> </p>
 *
 * @author ynding
 * @version 2022/4/26
 **/
@Repository
public class AccountRepositoryImpl implements AccountRepository {

    private WechatAccountDAO wechatAccountDAO;
    private WalletDAO walletDAO;
    private BalanceDAO balanceDAO;
    private StatementDAO statementDAO;

    @Override
    public void save(WechatAccount wechatAccount) {
        WechatAccountPO wechatAccountPO = WechatAccountConvert.convert(wechatAccount);
        wechatAccountDAO.save(wechatAccountPO);

        Wallet wallet = WalletFactory.obtain(wechatAccount);
        WalletPO walletPO = WalletConvert.convert(wallet);
        walletDAO.save(walletPO);

        Balance balance = BalanceFactory.obtain(wechatAccount);
        BalancePO balancePO = BalanceConvert.convert(balance);
        balanceDAO.save(balancePO);

        Statement statement = StatementFactory.obtain(wechatAccount);
        StatementPO statementPO = StatementConvert.convert(statement);
        statementDAO.save(statementPO);
    }

    @Override
    public WechatAccount findById(PhoneNumber phoneNumber) {
        return null;
    }
}
